package com.telit.common.config;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
import com.google.common.collect.Maps;
import com.telit.common.dto.SmsRealFireDto;
import com.telit.common.dto.SmsSuspectedFireDto;
import com.telit.common.dto.SmsVideoCameraDto;
import darabonba.core.client.ClientOverrideConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;


/**
 * @author yuzhanxiang
 * @description: 阿里云短信服务
 * @copyright 天立泰科技股份有限公司
 * @since 2022/4/1 15:44
 **/
@RequiredArgsConstructor
@Configuration
@SuppressWarnings("all")
public class SmsAliServerConfig {

    private static final String REGION_ID = "cn-hangzhou";
    private static final String ACCESS_KEY_ID = "LTAI5tQ2ypjxh6GmdC3Z2x3z";
    private static final String ACCESS_KEY_SECRET = "pHVaoZfhxcGIKwalcJPHnGCIRsOSWG";
    private static final String END_POINT = "dysmsapi.aliyuncs.com";
    private static final String SIGN_NAME = "天立泰科技";

    private static final Map<String, String> TEMPLATE_MAPPING = Maps.newConcurrentMap();
    private static final Map<String, Class<?>> TEMPLATE_PARAM_MAPPING = Maps.newConcurrentMap();


    // 临时处理不用枚举了  注意使用的时候请修改下述代码，有时间的同事看到后记得重写下述放进配置文件里
    static {
        //南京防火测试环境 -------start
        //南京防火-真实火情短信模板(含链接)
/*        TEMPLATE_MAPPING.put("1", "SMS_238471134");
        //南京防火-疑似火情短信模板(含链接)
        TEMPLATE_MAPPING.put("2", "SMS_239313921");
        //南京防火-摄像头-视频-报警
        TEMPLATE_MAPPING.put("3", "SMS_239314048");*/
        //南京防火测试环境 -------end

        //南京防火正式环境 -------start

//        //南京防火-真实火情短信模板(含链接)
//        TEMPLATE_MAPPING.put("1", "SMS_243045327");
//        //南京防火-疑似火情短信模板(含链接)
//        TEMPLATE_MAPPING.put("2", "SMS_243030309");
//        //南京防火-摄像头-视频-报警
//        TEMPLATE_MAPPING.put("3", "SMS_243115296");

        //安徽防火-真实火情短信模板(不含链接)
        TEMPLATE_MAPPING.put("1", "SMS_255325298");
        TEMPLATE_MAPPING.put("2", "SMS_276265448");

        //南京防火正式环境 -------end

        TEMPLATE_PARAM_MAPPING.put("1", SmsRealFireDto.class);
        TEMPLATE_PARAM_MAPPING.put("2", SmsSuspectedFireDto.class);
        TEMPLATE_PARAM_MAPPING.put("3", SmsVideoCameraDto.class);
    }

    /**
     * 获取签名
     *
     * @return 返回签名
     */
    public String getSignName() {
        return SIGN_NAME;
    }

    /**
     * 根据status 获取 参数class
     *
     * @param status
     * @return
     */
    public Class getParamClass(String status) {
        return TEMPLATE_PARAM_MAPPING.get(status);
    }

    /**
     * 根据status 获取 模板
     *
     * @param status
     * @return
     */
    public String getTemplate(String status) {
        return TEMPLATE_MAPPING.get(status);
    }

    @Bean
    public AsyncClient smsClient() {
        return AsyncClient.builder()
                .region(REGION_ID)
                .credentialsProvider(
                        StaticCredentialProvider
                                .create(Credential.builder()
                                        .accessKeyId(ACCESS_KEY_ID)
                                        .accessKeySecret(ACCESS_KEY_SECRET)
                                        //.securityToken("<your-token>") // use STS token
                                        .build()))
                .overrideConfiguration(
                        ClientOverrideConfiguration
                                .create()
                                .setEndpointOverride(END_POINT))
                .build();
    }
}
